//Supply truck by Nerro, modified by Spam_One


private ["_rad","_cnps","_hills","_hillcount","_hillnum","_hill","_marker","_checking","_people","_hillpos"];

sleep 300;
diag_log " Missions 5 launched";
[player,nil,rSIDECHAT,"An abandoned supply truck has been located, take it quickly and keep it for your vehicles maintenances."] call RE;
[nil,nil,rHINT,"An abandoned supply truck has been located, take it quickly and keep it for your vehicles maintenances."] call RE;
private ["_rad","_cnps","_hills","_hillcount","_hillnum","_hill","_marker"];

_rad=20000;
_cnps = getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition");
_hills = nearestLocations [_cnps, ["Hill"], _rad];
if (count _hills < 3) then {
	_hills = nearestLocations [_cnps,["FlatArea"],_rad];
};
if (count _hills < 2) then {
	_hills = towns; 
};
_hillcount = count _hills;
_hillnum = floor (random _hillcount);
_hill = _hills select _hillnum;
_hillpos = getpos _hill;

_marker_name ="";
_marker = "";
if (CVG_sideMarkers == 0) then {
	_marker_name = STR_MISSION_MARKER_1 + str (serverTime);
	_marker = createMarker [_marker_name,_hillpos];
	_marker setMarkerType "mil_destroy";
	_marker setMarkerColor "ColorGreen";
	_marker setMarkerText "Abandoned supply truck";
	_marker setMarkerSize [1,1];
};

if (CVG_sideMarkers == 1) then {
	_hillpos = [(_hillpos select 0) + random 100, (_hillpos select 1) + random 100,0];
	_marker_name = STR_MISSION_MARKER_1 + str (serverTime);
	_marker = createMarker [_marker_name,_hillpos];
	_marker setMarkerShape "ellipse";
	_marker setMarkerBrush "DiagGrid";
	_marker setMarkerColor "ColorGreen";
	_marker setMarkerText "Abandoned supply truck";
	_marker setMarkerSize [300,300];
};

missionActive = true;
missionVars = [_marker_name,_hillpos];
publicVariable "missionActive";
publicVariable "missionVars";

_truckArray = ["KamazReammo","KamazRefuel","KamazRepair"];
_chosen = _truckArray call BIS_fnc_selectRandom;
TRUCK = createVehicle [_chosen,[(getpos _hill select 0) + (floor random 100), (getpos _hill select 1) + (floor random 100),0],[], 0, "NONE"];
TRUCK setVehicleVarName _chosen;
TRUCK setFuel ((random .9)+.1);
TRUCK setDamage (random .9);

_checking = 1;

while {_checking == 1} do {
	_people = nearestObjects [[getpos TRUCK select 0, getpos TRUCK select 1,0],["LandVehicle", "Man"],150];
	if ({isPlayer _x} count _people > 0) then {_checking = 0};
	sleep 1;
};
{
    if (isPlayer _x) then {
        _victims = [];
        if (vehicle _x != _x) then { //in vehicle
            _victims = crew _x;
        } else {
            _victims = [_x];
        };
        
        {
	        _safePos = [_x, 50, 50, 75] call WF_FNCT_getRandomSafePos;
			
			trigger = createTrigger ["EmptyDetector", _safePos];
			trigger setTriggerArea [10,10,0,false];
			[trigger, 20, CLY_hordetrigger, "normal"] execVM  "WEFRAG\z_horde.sqf"; // horde exec
	        [_x, nil, rSIDECHAT, "Zombies are coming !"] call RE;
		} foreach (_victims);
    };
    
} forEach (nearestObjects [[getpos TRUCK select 0, getpos TRUCK select 1,0],["LandVehicle", "Man"],200]);

_checking = 1;
while {_checking == 1} do {
	_people = nearestObjects [[getpos TRUCK select 0, getpos TRUCK select 1,0],["LandVehicle", "Man"],50];
	if ({isPlayer _x} count _people > 0) then {_checking = 0};
	sleep 1;
};


[nil,nil,rHINT,"The abandoned supply truck has been found."] call RE;
deleteMarker _marker;
missionActive = false;
publicVariable "missionActive";


// hordes // Spam_One -------------------------------------------------------------------------

// putting a unit which we can rotate for finding a safe pos and randomize where hordes come from
// second Horde -------------------------------------------------------------------------------

/*_safePos = [TRUCK, 50, 50 , 75] call WF_FNCT_getRandomSafePos;

trigger2 = createTrigger ["EmptyDetector", _safePos];
trigger2 setTriggerArea [10,10,0,false];
[trigger2,18,CLY_hordetrigger,"normal"] execVM "zombie_scripts\cly_z_horde.sqf"; // horde exec
hint "second horde spawned";
sleep 20;
*/

// End of hordes ------------------------------------------------------------------------------
SM1 = 5;
[0] execVM "sideMissions\SMfinder.sqf";
